<template>
  <div class="container">
    <el-button
      type="primary"
      class="add"
      size="small"
      icon="el-icon-plus"
      style="margin-bottom: 15px"
      @click="handelAddServe"
    >
      添加
    </el-button>
    <el-table :data="dataSource">
      <el-table-column label="商标图片" prop="trademark_img">
        <template slot-scope="scope">
          <el-image
            style="width: 60px; height: 60px"
            :src="$store.getters.imgURL + scope.row.trademark_img"
            :preview-src-list="[
              $store.getters.imgURL + scope.row.trademark_img
            ]"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column label="商标名称" prop="title" />
      <el-table-column label="申请/注册号" prop="apply_code" />
      <el-table-column label="注册时间" prop="apply_time" />
      <el-table-column label="有效期至" prop="valid_time" />
      <!-- <el-table-column label="状态" prop="apply_time" /> -->

      <el-table-column label="创建时间" prop="create_time" />
      <el-table-column label="操作" width="200px" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            class="edit"
            @click="handelAddServe(scope.row)"
          >
            编辑
          </el-button>
          <el-button size="mini" class="dele" @click="handleDelete(scope.row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="page.currentPage"
      :page-sizes="page.pageSizes"
      :page-size="page.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total"
      :hide-on-single-page="page.total < page.size ? true : false"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import trademarkApi from '@/api/trademark'
export default {
  data() {
    return {
      dataSource: [],
      addShow: false,
      val: {},
      page: {
        total: 0,
        currentPage: 1,
        size: 10,
        pageSizes: [10, 20, 30, 40]
      } // 分页器
    }
  },
  mounted() {
    this.getListData()
  },
  methods: {
    handelAddServe(row = {}) {
      this.$router.push({
        name: 'addTrademark',
        query: {
          id: row.id
        }
      })
    },
    async getListData() {
      this.val.page = this.page.currentPage
      this.val.limit = this.page.size
      const res = await trademarkApi.trademarkList(this.val)
      this.dataSource = res.data
      this.page.total = res.count
    },
    async handleDelete(row) {
      const result = await this.$confirm(
        '此操作将永久删除改数据，是否继续?',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).catch(() => {})
      if (result == 'confirm') {
        const res = await trademarkApi.deleteTrademark({ id: row.id })
        if (res.code == 0) {
          this.getListData()
          this.$message.success(res.msg)
        } else {
          this.$message.error(res.msg)
        }
      }
    },
    // 分页规格改变
    handleSizeChange(val) {
      this.page.size = val
      this.page.currentPage = 1
      this.getListData()
    },
    // 分页点击
    handleCurrentChange(val) {
      this.page.currentPage = val
      this.getListData()
    }
  }
}
</script>

<style lang="scss" scope></style>
